(define (element-of-set? x set)
  (cond ((null? set) false)
        ((= x (car set)) true)
        ((< x (car set)) false)
        (else (element-of-set? x (cdr set)))))

(define (intersection-set set1 set2)
  (if (or (null? set1) (null? set2))
    '()
    (let ((x1 (car set1)) (x2 (car set2)))
     (cond ((= x1 x2)
            (cons x1 (intersection-set (cdr set1)
                                       (cdr set2))))
           ((< x1 x2)
            (intersection-set (cdr set1) set2))
           ((< x2 x1)
            (intersection-set set1 (cdr set2)))))))

(define (adjoin-set x set)
  (if (null? set)
    (list x)
    (let ((head (car set))
          (tail (cdr set)))
      (cond ((< x head) (cons x set))
            ((= x head) set)
            (else (cons head (adjoin-set x tail)))))))

(define (list->tree xs)
  (if (null? xs)
    '()
    (adjoin-set (car xs) (list->tree (cdr xs)))))
